# -*- coding: utf-8 -*-
# @File: backend => chat_messages.py
# @CreateTime: 2025/8/25 21:41
# @Author: EvanZhang
# @Info: 房间聊天消息

from tortoise import fields, models

# id | room_id | user_id | message | timestamp
class ChatMessage(models.Model):
    id = fields.IntField(pk=True)
    room = fields.ForeignKeyField('models.Room', related_name="chat_messages", description="所属房间")
    user = fields.ForeignKeyField("models.User", related_name="chat_messages", description="发送用户")
    message = fields.TextField(description="聊天消息内容")
    timestamp = fields.DatetimeField(auto_now_add=True, description="消息时间")

    class Meta:
        table = "chat_messages"
        description = "房间聊天消息表"
        index_together = (("room", "timestamp"),)
